#include <iostream>
#include <cstddef>

// int : 4 byte
// char: 1 byte

struct Person {
    int name;
    char sex; // 结构体末尾有 3 字节的填充，使总大小达到 8 字节
};

struct __attribute__((packed)) PersonPack {
    int name;
    char sex;
};

void Test() {
    std::cout << "Person=" << sizeof(Person) << std::endl;
    std::cout << "PersonPack=" << sizeof(PersonPack) << std::endl;
}

int main() {
    Test();
    
    // 额外信息：打印每个成员的偏移量
    std::cout << "\nPerson offset:" << std::endl;
    std::cout << "name offset: " << offsetof(Person, name) << std::endl;
    std::cout << "sex offset: " << offsetof(Person, sex) << std::endl;
    
    std::cout << "\nPersonPack offset:" << std::endl;
    std::cout << "name offset: " << offsetof(PersonPack, name) << std::endl;
    std::cout << "sex offset: " << offsetof(PersonPack, sex) << std::endl;
    
    return 0;
}